package com.vhdadw.controller;

import com.vhdadw.controller.request.TrafficPageRequest;
//import com.vhdadw.controller.request.UseTrafficRequest;
import com.vhdadw.controller.request.UseTrafficRequest;
import com.vhdadw.service.TrafficService;
import com.vhdadw.utils.JsonData;
import com.vhdadw.vo.TrafficVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/api/traffic/v1")
public class TrafficController {

    @Autowired
    private TrafficService trafficService;

    /**
     * 使用流量包api
     * @param useTrafficRequest
     * @param request
     * @return
     */
    @PostMapping("/reduce")
    public JsonData useTraffic(@RequestBody UseTrafficRequest useTrafficRequest, HttpServletRequest request){

        //具体使用流量包逻辑 TODO

        return JsonData.buildSuccess();
    }

    /**
     * 分页查询流量包列表，查看可用的流量包
     * @param request
     * @return
     */
    @RequestMapping("/page")
    public JsonData pageAvailable(@RequestBody TrafficPageRequest request){

        Map<String, Object> pagedAvailable = trafficService.pageAvailable(request);
        return JsonData.buildSuccess(pagedAvailable);
    }

    /**
     * 查找某个流量包详情
     * @return
     */
    @GetMapping("/detail/{trafficId}")
    public JsonData detail(@PathVariable("trafficId")Long trafficId){
        TrafficVO trafficVO = trafficService.detail(trafficId);
        return JsonData.buildSuccess(trafficVO);
    }
}
